//
//  WEBViewController.m
//  NewYzwShop
//
//  Created by krwlng on 15/11/5.
//  Copyright © 2015年 xmyzw. All rights reserved.
//  处理各种网络问题

#import "WEBViewController.h"


@interface WEBViewController ()<UIWebViewDelegate>
@property (nonatomic, strong)UIWebView * myWebView;
@property (nonatomic, strong) UIWindow *window;
@end

@implementation WEBViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.title = self.titleStr;
    

    self.myWebView = [[UIWebView alloc]init];
    self.myWebView.delegate = self;
    self.myWebView.x = 0;
    self.myWebView.y = 0;
    self.myWebView.width = GetWidth;
    self.myWebView.height = GetHeight - 64;



    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:self.url]];
    
    [self.myWebView loadRequest:request];

    [self.view addSubview:self.myWebView];

    
}

-(void)popBtnClick{
    if ([self.myWebView canGoBack]) {
        [self.myWebView goBack];
    }else{
        
        NSHTTPCookie *cookie;
        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (cookie in [storage cookies])
        {
            [storage deleteCookie:cookie];
        }
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    if (self.titleStr.length==0) {
        self.title = @"详情";
//    self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
    [self jsClick];
}
- (void)jsClick {
    [self.myWebView stringByEvaluatingJavaScriptFromString:@" "
     "$(function($) {"
     "$('.share').hide();"
     "setTimeout(function(){"
     "$('.feed-detail img').width('100%');"
     "},1000);"
     "});"
     "($('#myFlash').length > 0 ? $('#myFlash').parent() : $('.site_player')).siblings().hide()"
     ];

}

@end
